import {
  RolePageParams,
  RolePageListGetResultModel,
  RoleListItem,
  UploadRoleResult,
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';

enum Api {
  RolePageList = '/admin/role/page',

  InfoRole = '/admin/role',
  ADDRole = '/admin/role/add',
  DelRole = '/admin/role/del',
  UpdateRole = '/admin/role/update',
  ExportRole = '/admin/role/export',
  TempRole = '/admin/sys-file/local/file/role.xlsx',
  ImportRole = '/admin/role/import',
}
export const getRoleListByPage = (params?: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });

export const addRoleApi = (params: RoleListItem) => defHttp.post<any>({ url: Api.ADDRole, params });

export const getRoleInfoApi = (id: string) => defHttp.get<any>({ url: Api.InfoRole + '/' + id });

export const updateRoleApi = (params: RoleListItem) =>
  defHttp.post<any>({ url: Api.UpdateRole, params });

export const deleteRoleApi = (id: string) => defHttp.post<any>({ url: Api.DelRole + '/' + id });

export const exportRoleApi = () =>
  defHttp.get<any>(
    { url: Api.ExportRole, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export const tempRoleApi = () =>
  defHttp.get<any>(
    { url: Api.TempRole, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export function uploadRoleApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadRoleResult[]>(
    {
      url: Api.ImportRole,
      onUploadProgress,
    },
    params,
  );
}
